package servlet;

import service.impl.StudentServiceimpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/Educational/student/updatestudent")
public class UpdateStudentServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        String stuid1 = req.getParameter("stuid");
        int stuid = Integer.parseInt(stuid1);
        String stuname = req.getParameter("stuname");
        String stuno = req.getParameter("stuno");
        String sex1 = req.getParameter("sex");
        int sex = Integer.parseInt(sex1);
        String email = req.getParameter("email");
        String phone = req.getParameter("phone");
        String address = req.getParameter("address");
        String registered = req.getParameter("registered");
        String politics = req.getParameter("politics");
        String profession = req.getParameter("profession");
        String introduction = req.getParameter("introduction");
        String g = req.getParameter("gid");
        int gid = Integer.parseInt(g);
        String idnumber = req.getParameter("idnumber");
        StudentServiceimpl studentServiceimpl = new StudentServiceimpl();
        int k = studentServiceimpl.updateStudent(stuid, stuname, stuno, address, email, phone,
                idnumber, politics, registered, profession, introduction, gid, sex);
        resp.setContentType("text/html;charset= utf-8;");
        PrintWriter writer = resp.getWriter();
        if (k>0){
            resp.sendRedirect("/Educational/student/getstudents");
        }else{
            writer.println("<script>location.href='edit.jsp';alert('未成功更新'); </script>");
        }

    }
}
